package com.smkj.kaoqin.modules.student.service.impl;

import com.smkj.kaoqin.common.result.VResponse;
import com.smkj.kaoqin.common.utils.BaseContext;
import com.smkj.kaoqin.modules.common.pojo.db.Classes;
import com.smkj.kaoqin.modules.student.pojo.db.Student;
import com.smkj.kaoqin.modules.student.mapper.StudentMapper;
import com.smkj.kaoqin.modules.student.pojo.vo.ClassVO;
import com.smkj.kaoqin.modules.student.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 学生表 服务实现类
 * </p>
 *
 * @author yztyear
 * @since 2024-09-11
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public VResponse<ClassVO> queryClass() {
        ClassVO classVO = new ClassVO();
        //Long userId = Long.valueOf(BaseContext.getInfo());
        Long userId = 1L;
        Long studentNub = studentMapper.queryUser(userId).getAccount();
        //获取学生所有信息
        Student student = this.getById(studentNub);
        //把学号和姓名存入classVO
        BeanUtils.copyProperties(student,classVO);

        Long classId = Long.valueOf(student.getClassId());
        //获取班级所有信息
        Classes classes = studentMapper.queryClassById(classId);
        BeanUtils.copyProperties(classes,classVO);
        //计算班级人数
        Long numCount = studentMapper.ClassNumCount(classes.getClassName());
        classVO.setCount(numCount);
        return VResponse.success(classVO);
    }
}
